<?php
/**
 *装箱信息
 */
namespace app\controllers;

use app\models\ContainerModel;
use yii;

class ContainerController extends ApiBaseController
{
    /**
     * 装箱编号信息
     */
    public function actionNumber()
    {
        $where = [];
        $model = new ContainerModel();
        $list  = $model->getContainerNumByParam(['id', 'number', 'status'], $where);
        return json_encode(['list' => $list]);
    }

    /**
     *装箱收款财务审核
     */
    public function actionIncomeVerify()
    {
        if (!yii::$app->request->isPost) {
            return json_encode(['code' => 0, 'msg' => 'method not allowed']);
        }

        $id = yii::$app->request->post('id', 0);
        //id错误
        if ($id <= 0) {
            return json_encode(['code' => 0, 'msg' => 'data error']);
        }
        //只有管理员和财务可以
        if ($this->user['role'] != 1 && $this->user['role'] != 2) {
            return json_encode(['code' => 0, 'msg' => '没有权限']);
        }
        $model  = new ContainerModel();
        $res    = $model->save(['status' => 3], ['id' => $id]);
        $output = $res ? ['code' => 1, 'msg' => 'success'] : ['code' => 0, 'msg' => 'error'];
        return json_encode($output);
    }
}
